<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<title>报销申请管理</title>
<%@include file="/common/ec.jsp"%>
<%@include file="/common/extjs.jsp" %>
<%@include file="/common/meta.jsp"%>
<script type="text/javascript">
function remove(id){
	if (confirm("您确认要删除此报销申请单吗？")){
		window.location.href="${ctx}/reimb/remove.do?model.id=" + id;
	}
}
</script>
</head>
<body>
<div class="x-panel">
<div class="x-panel-header" >
	<div style="float: left;">【报销】申请管理</div>
	<div style="float: right;">
		<a href="${ctx}/reimb/edit.do"><img src="${ctx}/images/icons/add.gif" style="width: 12px; height: 12px;" />&nbsp;添加报销单</a>&nbsp;
        <a href="${ctx}/reimb/editParent.do"><img src="${ctx}/images/icons/add.gif" style="width: 12px; height: 12px;" />&nbsp;添加跨部门报销单</a>		
	</div>
</div>
<div class="x-toolbar">
  <table width="99%">
        <tr>
        <s:form action="index" theme="simple" id="form1">
	      <td>审批状态：</td> 
	      <td><s:select list='auditStatusMap' name="model.audStatus" cssStyle="width:65px" headerKey="" headerValue="全部"></s:select></td>        
	      <td>付款状态：</td> 
	      <td><s:select list='payStatusMap' name="model.payStatus" cssStyle="width:65px" headerKey="" headerValue="全部"></s:select></td>        
          <td>报销单号：</td>
          <td><s:textfield name="model.singleNo" cssStyle="width:130px;" />&nbsp;</td>
          <td>开始日期：</td>
          <td><input id="startDate" name="startDate" size="14"  value="<s:date name='startDate' format='yyyy-MM-dd'/>" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')}',skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="Wdate"  readonly="readonly"/>&nbsp;&nbsp;</td>
          <td>结束日期：</td>
          <td><input id="endDate" name="endDate" size="14" value=" <s:date name='endDate' format='yyyy-MM-dd'/>" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')}',skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="Wdate"  readonly="readonly"/></td>
          <td><s:submit value="查询" cssClass="button" cssStyle="width:45px;"></s:submit></td>
        </s:form>
      </table>
</div>
<div class="x-panel-body">
<ec:table items="items" var="item" retrieveRowsCallback="limit" sortRowsCallback="limit" 
	    action="index.do"
		useAjax="true" doPreload="false"
		maxRowsExported="10000000" 
		pageSizeList="15,50,100" 
		editable="false" 
		sortable="false"	
		rowsDisplayed="15"	
		generateScript="true"	
		resizeColWidth="false"	
		classic="false"	
		width="100%" 	
		height="400px"	
		minHeight="400"
		toolbarContent="navigation|pagejump|pagesize|refresh|extend|status">
	<ec:row style="height: auto;">
	    <ec:column width="30" property="_s" title="No." value="${GLOBALROWCOUNT}" sortable="false" style="text-align:center"/>
		<ec:column width="120" property="singleNo" title="报销单号">
      	    <a href="view.do?model.id=${item.id}" target="_blank" ><font color="blue">${item.singleNo}</font></a>
		</ec:column>				
	    <ec:column width="70" property="reimber.name" title="报销人" style="text-align:center"/>	
		<ec:column width="80" property="createDate" title="制单时间" style="text-align:center" cell="date"/>
		<ec:column width="80" property="amount" title="报销金额" style="text-align:right" format="#####0.00" cell="number"/>		
		<ec:column width="80" property="_borrowAmount" title="销账金额" style="text-align:right" format="#####0.00" cell="number">
		    <s:if test="#attr.item.borrowAmount != null">${item.borrowAmount}</s:if>
	        <s:else>0</s:else>
		</ec:column>
		<ec:column width="80" property="balance" title="余款" style="text-align:right" format="#####0.00" cell="number"/>
		<ec:column width="80" property="_audStatus" title="审批状态" style="text-align:center">
		  <s:if test="#attr.item.audStatus == 'unsend'"><font color="#999999">未审批</font></s:if>
		  <s:if test="#attr.item.audStatus == 'pending'"><font color="#000000">待审批</font></s:if>
		  <s:if test="#attr.item.audStatus == 'pass'"><font color="green">已通过</font></s:if>
		  <s:if test="#attr.item.audStatus == 'nopass'"><font color="red">未通过</font> </s:if>
		</ec:column>	
		<ec:column width="65" property="_payStatus" title="出纳付款" style="text-align:center">
		  <s:if test="#attr.item.payStatus == 0"><font color="#999999">未付款</font></s:if>
		  <s:if test="#attr.item.payStatus == 1"><font color="green">已付款</font></s:if>
		</ec:column>	 						
		        	
		<ec:column width="170" property="_0" title="操作" style="text-align:center" sortable="false">
		    <c:choose>
		      <c:when test="${item.audStatus != 'unsend'}">
			     <font color="#999999">编辑</font> | 		      
			     <font color="#999999">删除</font> | 
			     <font color="#999999">申请</font> |		     
		      </c:when>
		      <c:otherwise>
		         <s:if test="#attr.item.singleType == 0">
		      	   <a href="edit.do?model.id=${item.id}" title="${item.singleNo}">编辑</a> |
		      	 </s:if>
		      	 <s:else>
		      	   <a href="editParent.do?model.id=${item.id}" title="${item.singleNo}">编辑</a> |
		      	 </s:else> 
		      	 <a href="#" onclick="remove('${item.id}')" title="${item.singleNo}">删除</a> |  
		      	 
		      	 <s:if test="#attr.item.singleType == 0">
                   <a href="#" onclick="sendApply('${item.singleNo}', '${item.id}')" title="${item.singleNo}">申请</a> |
		      	 </s:if>
		      	 <s:else>
                   <a href="#" onclick="sendMoreApply('${item.singleNo}', '${item.id}')" title="${item.singleNo}">申请</a> |
		      	 </s:else> 
		      </c:otherwise>
		    </c:choose>

            <a href="view.do?model.id=${item.id}" target="_blank" title="${item.singleNo}">查看</a>

		</ec:column>
	</ec:row>
</ec:table>
</div>
</div>
<script type="text/javascript">
function sendApply(singleNo, reimbId){
    Ext.MessageBox.confirm('提示', '您确定发送【' + singleNo + '】的报销申请吗？', function(btn){
        if (btn == 'yes') {
        	//加载进度条
        	loadProgress();
        	
		      $.ajax({
		    	    url: '${ctx}/reimb/sendApply.do',
			  		type: 'post',
			  		dataType: 'json',
			  		data: {reimbId : reimbId},
			  		success: function(rst, textStatus){
			  	  		if(rst.result == "success"){ 
			  	  		    Ext.MessageBox.hide(); //隐藏进度条
		    		        Ext.MessageBox.show({
		    		             title:'提示',
		    		             minWidth:220,
		    		             msg:'<div style=\'width:180\';><br/>已成功发送报销申请！</div>',
		    		             buttons:Ext.MessageBox.OK,
		    		             icon:Ext.MessageBox.INFO,
		    		             fn:function (){refresh();}
		    		        });		    		        
			  	  	  	}			  	  		
			  	  		if(rst.result != "success"){	 
			  	  		    Ext.MessageBox.hide(); //隐藏进度条
		    		        Ext.MessageBox.show({
		    		             title:'提示',
		    		             minWidth:350,
		    		             msg:'<div style=\'width:320\';><br/>' + rst.result + '</div>',
		    		             buttons:Ext.MessageBox.OK,
		    		             icon:Ext.MessageBox.INFO
		    		        });
                            return false;
			  	  	  	}			  	  		
			  		}
			     });
       }
    });
}

function sendMoreApply(singleNo, reimbId){
    Ext.MessageBox.confirm('提示', '您确定发送【' + singleNo + '】的报销申请吗？', function(btn){
        if (btn == 'yes') {
        	//加载进度条
        	loadProgress();
        	
		      $.ajax({
		    	    url: '${ctx}/reimb/sendMoreApply.do',
			  		type: 'post',
			  		dataType: 'json',
			  		data: {reimbId : reimbId},
			  		success: function(rst, textStatus){
			  	  		if(rst.result == "success"){ 
			  	  		    Ext.MessageBox.hide(); //隐藏进度条
		    		        Ext.MessageBox.show({
		    		             title:'提示',
		    		             minWidth:220,
		    		             msg:'<div style=\'width:180\';><br/>已成功发送报销申请！</div>',
		    		             buttons:Ext.MessageBox.OK,
		    		             icon:Ext.MessageBox.INFO,
		    		             fn:function (){refresh();}
		    		        });		    		        
			  	  	  	}			  	  		
			  	  		if(rst.result != "success"){	 
			  	  		    Ext.MessageBox.hide(); //隐藏进度条
		    		        Ext.MessageBox.show({
		    		             title:'提示',
		    		             minWidth:350,
		    		             msg:'<div style=\'width:320\';><br/>' + rst.result + '</div>',
		    		             buttons:Ext.MessageBox.OK,
		    		             icon:Ext.MessageBox.INFO
		    		        });
                            return false;
			  	  	  	}			  	  		
			  		}
			     });
       }
    });
}

//加载进度条	
function loadProgress() {
	Ext.MessageBox.show({
		title : '提示',
		msg : '数据生成中,请耐心等待···',
		progress : true,
		width : 300,
		wait : true,
		waitConfig : {
			interval : 300,//0.6s进度条自动加载一定长度
			duration : 120000,
			fn : function() {
				Ext.MessageBox.hide();//让进度条消失
				Ext.MessageBox.show({
					title : '提示',
					minWidth : 220,
					minHeight : 220,
					msg : '系统超时！',
					buttons : Ext.MessageBox.OK
				//icon : Ext.MessageBox.INFO,
				});
			}
		},
		closable : true
	});
}

function refresh() {
  ECSideUtil.reload('ec');
}
</script>

</body>
</html>